# REPLICATION CODE FOR: "EMPHASIZING SIMILARITIES OR DIFFERENCES: FRAMING EFFECTS IN LGBTQ MOVEMENT MOBILIZATION"
# PHILIP EDWARD JONES
# 06/30/25

library(tidyverse)
library(haven)
library(scales)
library(survey)
library(readr)
library(jtools)
library(gtools)
library(flextable)
library(broom)
library(cowplot)
library(patchwork)

library(texreg)
library(marginaleffects)

# load all survey data
data <- read_rds("pgi2025.rds")

# themes for ggplots
theme_phil <- function(){
  theme(panel.background=element_rect(fill="gray91"), 
        axis.text.y=element_text(size=10, color="black") ,
        axis.text.x=element_text(size=8, color="black") ,
        axis.title=element_text(size=12, color="black"),
        plot.title=element_text(size=12, hjust=.5, face="bold"))
}
theme_phil2 <- function(){
  theme(panel.background=element_rect(fill="gray91"), 
        axis.text.y=element_text(size=8, color="black") ,
        axis.text.x=element_text(size=8, color="black") ,
        axis.title=element_text(size=12, color="black"),
        plot.title=element_text(hjust=.5, face="bold"))
}

# set random seed for simulations
set.seed(2022)

# create two datasets
# s.data: straight cisgender respondents
s.data <- data %>%
  filter(survey=="chet") %>%
  mutate(expt.cond=fct_relevel(expt.cond, "same"))
# q.data: lgbt respondents
q.data <- data %>%
  filter(survey=="lgbt") %>%
  mutate(expt.cond=fct_relevel(expt.cond, "same"))





############################################
# MANIPULATION/ATTENTION CHECKS
############################################

# Manipulation check: did views of what EF thought vary across conditions?
data %>%
  group_by(expt.cond) %>%
  summarize(
    ef.diff.mean = mean(manip.check, na.rm=T)*100)  # EF sees LGBTQ ppl as completely different (0) or same (1)  
tidy(lm(manip.check~expt.cond, data)) %>%
  mutate(signif=stars.pval(p.value))

# Attention checks
data %>%
  group_by(expt.cond) %>%
  summarize(
    attn1.mean = mean(attn.check1, na.rm=T),  # What was EF main concern? 
    attn2.mean = mean(attn.check2, na.rm=T))  # What did ad ask you to do?



############################################
# RESULTS: MODELS
############################################

# Relevel experimental condition factor
s.data$expt.cond <- fct_relevel(s.data$expt.cond, "control", "same")
q.data$expt.cond <- fct_relevel(q.data$expt.cond, "control", "same")

# Model for each DV, by survey: straight cisgender respondents
s.int <-  lm(ef_interest~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.act <-  lm(ef_act~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.ideo <- lm(ef_ideology~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.efft <- lm(ef_effective~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.trst <- lm(ef_trust~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.aggr <- lm(ef_aggressive~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.extr <- lm(ef_extreme~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.wlcm <- lm(ef_welcoming~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)

# Model for each DV, by survey: LGBT respondents
q.int <- lm(ef_interest~expt.cond, q.data)
q.act <- lm(ef_act~expt.cond, q.data)
q.ideo <- lm(ef_ideology~expt.cond, q.data)
q.efft <- lm(ef_effective~expt.cond, q.data)
q.trst <- lm(ef_trust~expt.cond, q.data)
q.aggr <- lm(ef_aggressive~expt.cond, q.data)
q.extr <- lm(ef_extreme~expt.cond, q.data)
q.wlcm <- lm(ef_welcoming~expt.cond, q.data)




############################################
# FIGURE 1: PREDICTED VALUES
############################################

# Choosing average values of IVs for simulations
library(marginaleffects)
mean(s.data$ft_lgbt, na.rm=T)
mean(s.data$know_lgb, na.rm=T)
mean(s.data$know_trans, na.rm=T)

# Predicted values of mobilization DVs
s.pr.mob <- bind_rows(
  predictions(s.int, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(s.act, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=c("control", "different", "same")), conf.level=.9),
  .id="source") %>%
  mutate(source=recode(source, `1`="s.int", `2`="s.act"))
q.pr.mob <- bind_rows(
  predictions(q.int, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(q.act, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  .id="source") %>%
  mutate(source=recode(source, `1`="q.int", `2`="q.act"))

# Predicted values of perceptions DVs
s.pr.perc <- bind_rows(
  predictions(s.ideo, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=levels(s.data$expt.cond)), conf.level=.9),
  predictions(s.efft, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=levels(s.data$expt.cond)), conf.level=.9),
  predictions(s.trst, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=levels(s.data$expt.cond)), conf.level=.9),
  predictions(s.aggr, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=levels(s.data$expt.cond)), conf.level=.9),
  predictions(s.extr, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=levels(s.data$expt.cond)), conf.level=.9),
  predictions(s.wlcm, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21, expt.cond=levels(s.data$expt.cond)), conf.level=.9),
  .id="source") %>%
  mutate(source=recode(source, `1`="s.ideo", `2`="s.efft", `3`="s.trst", `4`="s.aggr", `5`="s.extr", `6`="s.wlcm"))
q.pr.perc <- bind_rows(
  predictions(q.ideo, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(q.efft, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(q.trst, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(q.aggr, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(q.extr, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  predictions(q.wlcm, newdata=datagrid(expt.cond=c("control", "different", "same")), conf.level=.9),
  .id="source") %>%
  mutate(source=recode(source, `1`="q.ideo", `2`="q.efft", `3`="q.trst", `4`="q.aggr", `5`="q.extr", `6`="q.wlcm"))

# Everything in one dataframe
preds <- bind_rows(
  s.pr.mob,
  q.pr.mob,
  s.pr.perc,
  q.pr.perc,
  .id="source2") %>%
  mutate(source2=recode(source2, `1`="s.mob", `2`="q.mob", `3`="s.perc", `4`="q.perc"))

# Tidy dataframe
preds <- preds %>%
  separate(col=source2, into=c("survey", "dv.type"), convert=TRUE) %>%
  separate(col=source, into=c("survey", "dv"), convert=TRUE) %>%
  select(dv.type, survey:dv, expt.cond, dv, estimate, conf.low:conf.high) %>%
  mutate(expt.cond=fct_rev(expt.cond)) %>%
  mutate(expt.labl=str_to_upper(str_sub(expt.cond, 1,1))) %>%
  mutate(expt.labl=as.factor(expt.labl)) %>%
  mutate(expt.labl=fct_rev(expt.labl)) %>%
  mutate(dv=as.factor(dv)) %>%
  mutate(dv=fct_recode(dv,
                       "Take political action" = "act",
                       "Interest in group" = "int",
                       "Group was...welcoming" = "wlcm",
                       "...trustworthy" = "trst",
                       "Group's ideology" = "ideo",
                       "...extreme" = "extr",
                       "...effective" = "efft",
                       "...aggressive" =  "aggr"
  )) %>%
  mutate(dv=fct_rev(fct_relevel(dv, "Take political action", "Interest in group", "Group was...welcoming", "...trustworthy", "...effective", "...aggressive", "...extreme", "Group's ideology")))




# Figure 1
g1 <- ggplot(subset(preds, survey=="q"), 
             aes(x=dv, y=estimate, ymin=conf.low, ymax=conf.high, group=expt.labl)) +
  geom_errorbar(width=0, size=.55, position=position_dodge(.7))+
  geom_point(size=2.75, color="gray91", position=position_dodge(.7)) +
  geom_text(aes(label=expt.labl), position=position_dodge(.7), size=2.75) +
  scale_y_continuous(limits=c(0, 1), breaks=seq(from=0, to=1, by=.2)) +
  ylab("Predicted value") + xlab(NULL) +
  coord_flip() +
  theme_phil()
g1 <- g1 + facet_grid(dv.type~., scales="free", space="free_y") + theme(strip.text=element_blank()) +
  ggtitle("(b) Predicted values for LGBT respondents")

g2 <- ggplot(subset(preds, survey=="s"), 
             aes(x=dv, y=estimate, ymin=conf.low, ymax=conf.high, group=expt.labl)) +
  geom_errorbar(width=0, size=.55, position=position_dodge(.7))+
  geom_point(size=2.75, color="gray91", position=position_dodge(.7)) +
  geom_text(aes(label=expt.labl), position=position_dodge(.7), size=2.75) +
  scale_y_continuous(limits=c(0, 1), breaks=seq(from=0, to=1, by=.2)) +
  ylab("Predicted value") + xlab(NULL) +
  coord_flip() +
  theme_phil()
g2 <- g2 + facet_grid(dv.type~., scales="free", space="free_y") + theme(strip.text=element_blank()) +
  ggtitle("(a) Predicted values for straight cisgender respondents")

library(patchwork)
g2 + g1
ggsave("Fig1.pdf", width=12.5, height=7)





############################################################
# FIGURE 2: ATEs
############################################################

# panels (a) and (b), ATEs of each treatment relative to control

s.fd.mob <- bind_rows(
  summary(marginaleffects(s.int, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  summary(marginaleffects(s.act, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="s.int", `2`="s.act")) %>%
  mutate(expt.label=recode(contrast,
                           `mean(same) - mean(control)`="S",
                           `mean(different) - mean(control)`="D"))


q.fd.mob <- bind_rows(
  summary(marginaleffects(q.int, conf.level=.95))[1:2,],
  summary(marginaleffects(q.act, conf.level=.95))[1:2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="q.int", `2`="q.act")) %>%
  mutate(expt.label=recode(contrast,
                           `mean(same) - mean(control)`="S",
                           `mean(different) - mean(control)`="D"))


s.fd.perc <- bind_rows(
  summary(marginaleffects(s.ideo, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  summary(marginaleffects(s.efft, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  summary(marginaleffects(s.trst, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  summary(marginaleffects(s.aggr, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  summary(marginaleffects(s.extr, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
  summary(marginaleffects(s.wlcm, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21), conf.level=.95))[1:2,],
    .id="source") %>%
  mutate(source=recode(source, `1`="s.ideo", `2`="s.efft", `3`="s.trst", `4`="s.aggr", `5`="s.extr", `6`="s.wlcm")) %>%
  mutate(expt.label=recode(contrast,
                           `mean(same) - mean(control)`="S",
                           `mean(different) - mean(control)`="D"))


q.fd.perc <- bind_rows(
  summary(marginaleffects(q.ideo, conf.level=.95))[1:2,],
  summary(marginaleffects(q.efft, conf.level=.95))[1:2,],
  summary(marginaleffects(q.trst, conf.level=.95))[1:2,],
  summary(marginaleffects(q.aggr, conf.level=.95))[1:2,],
  summary(marginaleffects(q.extr, conf.level=.95))[1:2,],
  summary(marginaleffects(q.wlcm, conf.level=.95))[1:2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="q.ideo", `2`="q.efft", `3`="q.trst", `4`="q.aggr", `5`="q.extr", `6`="q.wlcm")) %>%
  mutate(expt.label=recode(contrast,
                           `mean(same) - mean(control)`="S",
                           `mean(different) - mean(control)`="D"))


fds1 <- bind_rows(
  s.fd.mob,
  q.fd.mob,
  s.fd.perc,
  q.fd.perc,
  .id="source2") %>%
  mutate(source2=recode(source2, `1`="s.mob", `2`="q.mob", `3`="s.perc", `4`="q.perc"))


fds1 <- fds1 %>%
  separate(col=source2, into=c("survey", "dv.type"), convert=TRUE) %>%
  separate(col=source, into=c("survey", "dv"), convert=TRUE) %>%
  select(dv.type, survey:dv, estimate, conf.low:expt.label) %>%
  mutate(expt.label=fct_rev(as.factor(expt.label))) %>%
  mutate(dv=as.factor(dv)) %>%
  mutate(dv=fct_recode(dv,
                       "Interest in group" = "int",
                       "Take political action" = "act",
                       "Group was...welcoming" = "wlcm",
                       "...trustworthy" = "trst",
                       "Group's ideology" = "ideo",
                       "...extreme" = "extr",
                       "...effective" = "efft",
                       "...aggressive" =  "aggr"
  )) %>%
  mutate(dv=fct_rev(fct_relevel(dv, "Take political action", "Interest in group", "Group was...welcoming", "...trustworthy", "...effective", "...aggressive", "...extreme", "Group's ideology")))


# panel a
f2_a <- ggplot(subset(fds1, survey=="s"), 
             aes(x=dv, y=estimate, ymin=conf.low, ymax=conf.high, group=expt.label)) +
  geom_hline(yintercept=0, color="gray5", linetype=2, size=.5) +
  geom_errorbar(width=0, size=.55, position=position_dodge(.6))+
  geom_point(size=3, color="gray91", position=position_dodge(.6)) +
  geom_text(aes(label=expt.label), position=position_dodge(.6), size=3) +
  scale_y_continuous(limits=c(-.4, .4)) +
  ylab("ATE relative to control condition") + xlab(NULL) +
  coord_flip() +
  theme_phil()
f2_a <- f2_a + facet_grid(dv.type~., scales="free", space="free_y") + theme(strip.text=element_blank()) +
  ggtitle("(a) Effect relative to control condition\nfor straight cisgender respondents")


# panel b
f2_b <- ggplot(subset(fds1, survey=="q"), 
             aes(x=dv, y=estimate, ymin=conf.low, ymax=conf.high, group=expt.label)) +
  geom_hline(yintercept=0, color="gray5", linetype=2, size=.5) +
  geom_errorbar(width=0, size=.55, position=position_dodge(.6))+
  geom_point(size=3, color="gray91", position=position_dodge(.6)) +
  geom_text(aes(label=expt.label), position=position_dodge(.6), size=3) +
  scale_y_continuous(limits=c(-.4, .4)) +
  ylab("ATE relative to control condition") + xlab(NULL) +
  coord_flip() +
  theme_phil()
f2_b <- f2_b + facet_grid(dv.type~., scales="free", space="free_y") + theme(strip.text=element_blank()) +
  ggtitle("(b) Effect relative to control condition\nfor LGBT respondents")


# panels (c) and (d), ATEs of differences treatment relative to similarities
s.data <- data %>%
  filter(survey=="chet") %>%
  mutate(expt.cond=fct_relevel(expt.cond, "same"))
q.data <- data %>%
  filter(survey=="lgbt") %>%
  mutate(expt.cond=fct_relevel(expt.cond, "same"))

s.int <-  lm(ef_interest~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.act <-  lm(ef_act~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.ideo <- lm(ef_ideology~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.efft <- lm(ef_effective~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.trst <- lm(ef_trust~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.aggr <- lm(ef_aggressive~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.extr <- lm(ef_extreme~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)
s.wlcm <- lm(ef_welcoming~expt.cond+ft_lgbt+know_lgb+know_trans, s.data)

q.int <- lm(ef_interest~expt.cond, q.data)
q.act <- lm(ef_act~expt.cond, q.data)
q.ideo <- lm(ef_ideology~expt.cond, q.data)
q.efft <- lm(ef_effective~expt.cond, q.data)
q.trst <- lm(ef_trust~expt.cond, q.data)
q.aggr <- lm(ef_aggressive~expt.cond, q.data)
q.extr <- lm(ef_extreme~expt.cond, q.data)
q.wlcm <- lm(ef_welcoming~expt.cond, q.data)

s.fd.mob2 <- bind_rows(
  summary(marginaleffects(s.int, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  summary(marginaleffects(s.act, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="s.int", `2`="s.act"))  

q.fd.mob2 <- bind_rows(
  summary(marginaleffects(q.int))[2,],
  summary(marginaleffects(q.act))[2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="q.int", `2`="q.act"))  

s.fd.perc2 <- bind_rows(
  summary(marginaleffects(s.ideo, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  summary(marginaleffects(s.efft, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  summary(marginaleffects(s.trst, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  summary(marginaleffects(s.aggr, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  summary(marginaleffects(s.extr, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  summary(marginaleffects(s.wlcm, newdata=datagrid(ft_lgbt=.58, know_lgb=.7, know_trans=.21)))[2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="s.ideo", `2`="s.efft", `3`="s.trst", `4`="s.aggr", `5`="s.extr", `6`="s.wlcm"))

q.fd.perc2 <- bind_rows(
  summary(marginaleffects(q.ideo))[2,],
  summary(marginaleffects(q.efft))[2,],
  summary(marginaleffects(q.trst))[2,],
  summary(marginaleffects(q.aggr))[2,],
  summary(marginaleffects(q.extr))[2,],
  summary(marginaleffects(q.wlcm))[2,],
  .id="source") %>%
  mutate(source=recode(source, `1`="q.ideo", `2`="q.efft", `3`="q.trst", `4`="q.aggr", `5`="q.extr", `6`="q.wlcm"))


fds2 <- bind_rows(
  s.fd.mob2,
  q.fd.mob2,
  s.fd.perc2,
  q.fd.perc2,
  .id="source2") %>%
  mutate(source2=recode(source2, `1`="s.mob", `2`="q.mob", `3`="s.perc", `4`="q.perc"))


fds2 <- fds2 %>%
  separate(col=source2, into=c("survey", "dv.type"), convert=TRUE) %>%
  separate(col=source, into=c("survey", "dv"), convert=TRUE) %>%
  select(dv.type, survey:dv, estimate, conf.low, conf.high) %>%
  mutate(dv=as.factor(dv)) %>%
  mutate(dv=fct_recode(dv,
                       "Interest in group" = "int",
                       "Take political action" = "act",
                       "Group was...welcoming" = "wlcm",
                       "...trustworthy" = "trst",
                       "Group's ideology" = "ideo",
                       "...extreme" = "extr",
                       "...effective" = "efft",
                       "...aggressive" =  "aggr"
  )) %>%
  mutate(dv=fct_rev(fct_relevel(dv, "Take political action", "Interest in group", "Group was...welcoming", "...trustworthy", "...effective", "...aggressive", "...extreme", "Group's ideology")))


# plot (c)
f2_c <- ggplot(subset(fds2, survey=="s"), 
             aes(x=dv, y=estimate, ymin=conf.low, ymax=conf.high)) +
  geom_hline(yintercept=0, color="gray5", linetype=2, size=.5) +
  geom_errorbar(width=0, size=.55)+
  geom_point(size=3, color="gray91") +
  geom_text(aes(label="D"), size=3) +
  scale_y_continuous(limits=c(-.4, .4)) +
  ylab("ATE relative to similarities condition") + xlab(NULL) +
  coord_flip() +
  theme_phil()
f2_c <- f2_c + facet_grid(dv.type~., scales="free", space="free_y") + theme(strip.text=element_blank()) +
  ggtitle("(c) Effect relative to similarities condition\nfor straight cisgender respondents")

# plot (d)
f2_d <- ggplot(subset(fds2, survey=="q"), 
               aes(x=dv, y=estimate, ymin=conf.low, ymax=conf.high)) +
  geom_hline(yintercept=0, color="gray5", linetype=2, size=.5) +
  geom_errorbar(width=0, size=.55)+
  geom_point(size=3, color="gray91") +
  geom_text(aes(label="D"), size=3) +
  scale_y_continuous(limits=c(-.4, .4)) +
  ylab("ATE relative to similarities condition") + xlab(NULL) +
  coord_flip() +
  theme_phil()
f2_d <- f2_d + facet_grid(dv.type~., scales="free", space="free_y") + theme(strip.text=element_blank()) +
  ggtitle("(d) Effect relative to similarities condition\nfor LGBT respondents")


# FIGURE 2

(f2_a + f2_b) / plot_spacer() / (f2_c + f2_d) + plot_layout(heights=c(1,.05,.9))
ggsave("Fig2.pdf", width=12.5, height=15)




################################################################################
# Exploring potential heterogeneous treatment effects
################################################################################

s.data$expt.cond <- fct_relevel(s.data$expt.cond, "same")
q.data$expt.cond <- fct_relevel(q.data$expt.cond,  "same")


# by LGBT feeling thermometer
s.int <- lm(ef_interest~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.act <- lm(ef_act~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.ideo <- lm(ef_ideology~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.efft <- lm(ef_effective~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.trst <- lm(ef_trust~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.aggr <- lm(ef_aggressive~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.extr <- lm(ef_extreme~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)
s.wlcm <- lm(ef_welcoming~expt.cond*ft_lgbt+know_lgb+know_trans, s.data)

fd.int <- comparisons(s.int, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "int") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.act <- comparisons(s.act, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "act") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.ideo <- comparisons(s.ideo, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "ideo") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.efft <- comparisons(s.efft, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "efft") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.trst <- comparisons(s.trst, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "trst") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.aggr <- comparisons(s.aggr, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "aggr") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.extr <- comparisons(s.extr, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "extr") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)
fd.wlcm <- comparisons(s.wlcm, newdata = datagrid(ft_lgbt = seq(from=0, to=1, by=.1), know_lgb=.7, know_trans=.21), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "wlcm") %>%
  select(dv, ft_lgbt, estimate, conf.low, conf.high)


s.fd.mob <- bind_rows(
  fd.int, fd.act)
s.fd.perc <- bind_rows(
  fd.ideo, fd.efft, fd.trst, fd.aggr, fd.extr, fd.wlcm)
  

fds <- bind_rows(
  s.fd.mob,
  s.fd.perc,
  .id="source") %>%
  mutate(source=recode(source, `1`="s.mob", `2`="s.perc")) %>%
  mutate(dv=as.factor(dv)) %>%
  mutate(dv=fct_recode(dv,
                       "(b) Interest in group" = "int",
                       "(a) Take political action" = "act",
                       "(c) Group was welcoming" = "wlcm",
                       "(d) Group was trustworthy" = "trst",
                       "(h) Group's ideology" = "ideo",
                       "(g) Group was extreme" = "extr",
                       "(e) Group was effective" = "efft",
                       "(f) Group was aggressive" =  "aggr"
  )) %>%
  mutate(dv=(fct_relevel(dv, "(a) Take political action", "(b) Interest in group", "(c) Group was welcoming", 
                         "(d) Group was trustworthy", "(e) Group was effective", "(f) Group was aggressive", 
                         "(g) Group was extreme", "(h) Group's ideology")),
         ft_lgbt=ft_lgbt*100)



g1 <- ggplot(fds, aes(x=ft_lgbt, y=estimate, ymin=conf.low, ymax=conf.high)) +
  geom_ribbon(alpha=.3) +
  geom_hline(yintercept=0, color="gray5", linetype=2, size=.5) +
  geom_line(size=1.5) +
  scale_y_continuous(limits=c(-.3, .3), breaks=c(-.3, -.2, -.1, 0, .1, .2, .3)) + ylab("Effect of LGBT differences condition\n") + xlab("\nLGBT feeling thermometer") +
  theme_phil2()

g1 + facet_wrap(.~dv, nrow=2) + 
  theme(strip.text=element_text(face="bold", size=10), strip.background = element_rect(fill="white"), panel.spacing = unit(2, "lines"))
ggsave("Fig3.pdf", width=11, height=7)


# by interpersonal contact
s.act <- lm(ef_ideology~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.int <- lm(ef_ideology~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.ideo <- lm(ef_ideology~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.efft <- lm(ef_effective~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.trst <- lm(ef_trust~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.aggr <- lm(ef_aggressive~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.extr <- lm(ef_extreme~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.wlcm <- lm(ef_welcoming~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)

mods1 <- list(s.act, s.int, s.wlcm, s.trst)
mods2 <- list(s.efft, s.aggr, s.extr, s.ideo)
texreg(mods1, single.row=T, booktabs=T, caption.above=T, dcolumn=T, stars=c(.001, .01, .05, .1), symbol="\\dagger", fontsize="small", include.deviance=F, include.dispersion=F)
texreg(mods2, single.row=T, booktabs=T, caption.above=T, dcolumn=T, stars=c(.001, .01, .05, .1), symbol="\\dagger", fontsize="small", include.deviance=F, include.dispersion=F)

s.data$expt.cond <- fct_relevel(s.data$expt.cond, "same")
s.act <- lm(ef_ideology~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.int <- lm(ef_ideology~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.ideo <- lm(ef_ideology~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.efft <- lm(ef_effective~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.trst <- lm(ef_trust~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.aggr <- lm(ef_aggressive~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.extr <- lm(ef_extreme~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)
s.wlcm <- lm(ef_welcoming~expt.cond*know_lgb+expt.cond*know_trans+ft_lgbt, s.data)


fd.int <- comparisons(s.int, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "int") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)
fd.act <- comparisons(s.act, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "act") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)


fd.ideo <- comparisons(s.ideo, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "ideo") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)
fd.efft <- comparisons(s.efft, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "efft") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)
fd.trst <- comparisons(s.trst, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "trst") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)
fd.aggr <- comparisons(s.aggr, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "aggr") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)
fd.extr <- comparisons(s.extr, newdata = datagrid(know_lgb= c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "extr") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)
fd.wlcm <- comparisons(s.wlcm, newdata = datagrid(know_lgb = c(0,1), ft_lgbt=.58), variables = "expt.cond") %>%
  filter(contrast=="different - same") %>%
  mutate(conf.low = estimate-(1.96*std.error),
         conf.high = estimate+(1.96*std.error),
         dv = "wlcm") %>%
  select(dv, know_lgb, estimate, conf.low, conf.high)


s.fd.mob <- bind_rows(
  fd.int, fd.act)

s.fd.perc <- bind_rows(
  fd.ideo, fd.efft, fd.trst, fd.aggr, fd.extr, fd.wlcm)


fds <- bind_rows(
  s.fd.mob,
  s.fd.perc,
  .id="source") %>%
  mutate(source=recode(source, `1`="s.mob", `2`="s.perc")) %>%
  mutate(dv=as.factor(dv)) %>%
  mutate(dv=fct_recode(dv,
                       "(b) Interest in group" = "int",
                       "(a) Take political action" = "act",
                       "(c) Group was welcoming" = "wlcm",
                       "(d) Group was trustworthy" = "trst",
                       "(h) Group's ideology" = "ideo",
                       "(g) Group was extreme" = "extr",
                       "(e) Group was effective" = "efft",
                       "(f) Group was aggressive" =  "aggr"
  )) %>%
  mutate(dv=(fct_relevel(dv, "(a) Take political action", "(b) Interest in group", "(c) Group was welcoming", 
                         "(d) Group was trustworthy", "(e) Group was effective", "(f) Group was aggressive", 
                         "(g) Group was extreme", "(h) Group's ideology")))


g1 <- ggplot(fds, aes(x=know_lgb, y=estimate, ymin=conf.low, ymax=conf.high)) +
  geom_point(size=2.5) + geom_errorbar(width=.05) +
  geom_hline(yintercept=0, color="gray5", linetype=2, size=.5) +
  scale_y_continuous(limits=c(-.3, .3), breaks=c(-.3, -.2, -.1, 0, .1, .2, .3)) + ylab("Effect of LGBT differences condition\n") + xlab("\nInterpersonal contact with LGB people") +
  scale_x_continuous(breaks=c(0,1), labels=c("No", "Yes"), limits=c(-.3,1.3)) +
  theme_phil2()

g1 + facet_wrap(.~dv, nrow=2) + 
  theme(strip.text=element_text(face="bold", size=10), strip.background = element_rect(fill="white"), panel.spacing = unit(2, "lines"))

ggsave("FigA1.pdf", width=11, height=7)



